package logic

import (
	"context"
	"errors"
	"video/mysql/model"

	"video/videorpc/internal/svc"
	"video/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewVideoShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoShowLogic {
	return &VideoShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *VideoShowLogic) VideoShow(in *videorpc.VideoShowRequest) (*videorpc.VideoShowResponse, error) {
	// todo: add your logic here and delete this line

	var video model.Video
	model.DB.Debug().Where("id = ?", in.VideoId).Find(&video)
	if video.ID == 0 {
		return nil, errors.New("当前视频不存在")
	}

	return &videorpc.VideoShowResponse{
		VideoId:     int64(video.ID),
		Title:       video.Title,
		VideoClass:  video.VideoClass,
		Image:       video.Image,
		Info:        video.Info,
		VideoStatus: video.VideoStatus,
		UserId:      video.UserId,
	}, nil
}
